package com.chenglu.android.restaurant.shop.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;

public class CustomScrollView extends NestedScrollView {
    int originScroll=0;
    int mLooperHeaderHeight=0;
    public CustomScrollView(@NonNull Context context) {
        super(context);
    }

    public CustomScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomScrollView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public void onNestedPreScroll(@NonNull View target, int dx, int dy, @NonNull int[] consumed, int type) {
        if(originScroll<mLooperHeaderHeight){
            scrollBy(dx,dy);
        consumed[0] = dx;
        consumed[1] = dy;
        }
        super.onNestedPreScroll(target, dx, dy, consumed, type);

    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        this.originScroll = t;
        super.onScrollChanged(l, t, oldl, oldt);

    }

    //获得NestedscroLView中除去RecycLerView部分的高度
    public void setLooperHeaderHeight(int LooperHeaderHeight){
        this.mLooperHeaderHeight = LooperHeaderHeight;
    }
}
